package com.yuexunit.operationman.nbsy.module.OperationInventory.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;


import com.yuexunit.operationman.nbsy.R;
import com.yuexunit.operationman.nbsy.base.BaseKJActivity;
import com.yuexunit.operationman.nbsy.config.AppConfig;
import com.yuexunit.operationman.nbsy.module.OperationInventory.bean.InventoryBean;
import com.yuexunit.operationman.nbsy.module.OperationInventory.model.impl.InventoryDetailModel;
import com.yuexunit.operationman.nbsy.module.OperationInventory.presenter.IInventoryDetailPresenter;
import com.yuexunit.operationman.nbsy.module.OperationInventory.presenter.impl.InventoryDetailPresenter;
import com.yuexunit.operationman.nbsy.module.OperationInventory.ui.view.IInventoryDetailView;
import com.yuexunit.operationman.nbsy.widget.LoadingDialog;

import org.kymjs.kjframe.utils.PreferenceHelper;

import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by chenss on 2017/8/14 0014.
 */

public class Act_OperationInventory_Main extends BaseKJActivity implements IInventoryDetailView {

    @Bind(R.id.name)
    TextView name;
    @Bind(R.id.age)
    TextView age;
    @Bind(R.id.sex)
    TextView sex;
    @Bind(R.id.oprate_date)
    TextView oprateDate;
    @Bind(R.id.bedID)
    TextView bedID;
    @Bind(R.id.admission_number)
    TextView admissionNumber;
    @Bind(R.id.titlebar_tv_title)
    TextView titlebarTvTitle;

    IInventoryDetailPresenter presenter;

    LoadingDialog loadingDialog;

    @Override
    public void setRootView() {
        setContentView(R.layout.act_operationinventory_main);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        super.initData();
        setTitle();
        loadingDialog = new LoadingDialog(this);
        presenter = new InventoryDetailPresenter(this,new InventoryDetailModel());
    }

    @Override
    public void onResume(){
        super.onResume();
        Map<String, String> params = new HashMap<>();
        params.put("operationNo", PreferenceHelper.readString(aty, AppConfig.PATIENT_INFO, AppConfig.PATIENT_OPERATION_ID)+"");
        presenter.getInventoryDate(params);
    }

    private void setTitle()
    {
        titlebarTvTitle.setText("手术清点单");
    }


    @OnClick({R.id.titlebar_img_back, R.id.operation_inventory, R.id.operation_sign, R.id.preview})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.titlebar_img_back:
                finish();
                break;
            case R.id.operation_inventory:
                if( AppConfig.INVENTORYBEAN.getObject().getCheck().getCheckId()!=null)
                {

                    Bundle bundle = new Bundle();
                    bundle.putSerializable("goods",AppConfig.INVENTORYBEAN.getObject().getCheckItemList());
                    bundle.putBoolean("isFirst",false);
                    Intent intent2 = new Intent(aty, Act_OperationInventory_GoodsList.class);
                    intent2.putExtras(bundle);
                    startActivity(intent2);
                }
                else {
                    startActivity(new Intent(aty, Act_OperationInventory_Templet.class));
                }
                break;
            case R.id.operation_sign:
                startActivity(new Intent(aty, Act_OperationInventory_Sign.class));
                break;
            case R.id.preview:
                startActivity(new Intent(aty, Act_OperationInventory_Preview.class));
                break;
        }
    }

    @Override
    public void getInventoryDate(InventoryBean inventoryBean) {
        if(inventoryBean.getCode() == 200)
        {
            AppConfig.INVENTORYBEAN =inventoryBean;
            name.setText(AppConfig.INVENTORYBEAN.getObject().getCheck().getPatientName());
            age.setText(AppConfig.INVENTORYBEAN.getObject().getCheck().getPatientAge());
            if(AppConfig.INVENTORYBEAN.getObject().getCheck().getPatientSex().equals("1")) {
                sex.setText("男");
            }else if(AppConfig.INVENTORYBEAN.getObject().getCheck().getPatientSex().equals("2"))
            {
                sex.setText("女");
            }
            else {
                sex.setText("不详");
            }
            oprateDate.setText(AppConfig.INVENTORYBEAN.getObject().getCheck().getOperationDateStr());
            bedID.setText(AppConfig.INVENTORYBEAN.getObject().getCheck().getPatientBed());
            admissionNumber.setText(AppConfig.INVENTORYBEAN.getObject().getCheck().getInHospitalNo());
        }
    }

    @Override
    public void loadingDialogStatus(int status) {
        switch (status) {
            case AppConfig.SHOW_DIALOG:
                loadingDialog.setCanceledOnTouchOutside(false);
                loadingDialog.show();
                break;
            case AppConfig.DISMISS_DIALOG:
                loadingDialog.dismiss();
                break;

        }
    }
}
